﻿using UnityEngine;
using TinyWnd;

public class WRankDetail : MonoBehaviour
{
    UISprite sprite;
    UILabel label;
    GameObject btn;
    TweenPosition twPosition;
    GameObject btnGo;

    void Awake()
    {
        var tran = transform;
        sprite = Utility.FindChild<UISprite>(tran, "Bg/Bg/Equip");
        label = Utility.FindChild<UILabel>(tran, "Bg/Bg/Equip/Label");
        btn = Utility.FindChild(tran, "Bg").gameObject;
        twPosition = btn.GetComponent<TweenPosition>();
        btnGo = Utility.FindChild(tran, "Bg/BtnGoLevel").gameObject;

        UIEventListener.Get(btn).onClick = delegate
        {
            ClickBg();
        };

        UIEventListener.Get(btnGo).onClick = delegate
        {
            WndMgr.inst.ShowWindow(WndId.level);
        };
    }

    void ClickBg()
    {
        var w = WndMgr.inst.GetWnd<RankWnd>(WndId.rank);
        if (w != null)
            w.HideRankDetail();
    }

    public void InitDetail(RankItemData data)
    {
        sprite.spriteName = data.spriteName;
        label.text = data.lblName;
        twPosition.PlayForward();
    }

    public void HideDetail()
    {
        twPosition.PlayReverse();
    }
}
